from fastapi import HTTPException

class BaseError(Exception):
    """应用基础异常类"""
    def __init__(self, code: int, message: str):
        self.code = code
        self.message = message
        super().__init__(self.message)
        
class ResourceNotFoundError(BaseError):
    """资源未找到异常"""
    def __init__(self, message: str = "资源未找到"):
        super().__init__(code=404, message=message)

class ValidationError(BaseError):
    """请求数据校验错误"""
    def __init__(self, message: str = "请求数据验证失败"):
        super().__init__(code=400, message=message)

class DatabaseError(BaseError):
    """数据库操作异常"""
    def __init__(self, message: str = "数据库操作失败"):
        super().__init__(code=500, message=message)

class AuthenticationError(BaseError):
    """认证异常（身份验证失败）"""
    def __init__(self, message: str = "认证失败"):
        super().__init__(code=401, message=message)

class AuthorizationError(BaseError):
    """授权异常（权限验证失败）"""
    def __init__(self, message: str = "权限不足"):
        super().__init__(code=403, message=message)
